-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite the clearart method in order to send write events to the plugins. #1565
Conversation
Cool! Thank you for simultaneously simplifying the code while making it more correct. ✨ A test for this could just assert that the appropriate event gets sent (using a dummy plugin) when the art is cleared. Would that work? It would still be nice to remove the art tag altogether. Maybe we could refine the interface for |
Thank you for your input! I will try to come up with a test soon. I also looked at how tags could be removed from the file with the *See: https://github.com/sampsyo/beets/blob/master/beets/mediafile.py#L1502 |
Nice! That should do it. Thanks for sorting that out. |
I added 2 commits with a first shot at testing event sending. However, the test suite fails, here's the output for a single test:
I'm willing to investigate the assertion fail, but I've got no idea on how to take the mutagen errors. (Regarding the assertion error, the previous fix works on my machine (TM) with regular, non dummy files). I'll probably still try to tackle this anyway tomorrow or in the rest of the week, but any help with mutagen and fixtures would be appreciated. 🙏 |
That's certainly odd. I don't quite see what's going wrong here, but I do think you might be testing at the wrong level. You want to test the Perhaps you want to put a test in The event-capturing plugin fixture looks good, though! |
Oh you're totally right. I'll give it another try. |
Just a quick update: I've got some family stuff getting in the way of writing the tests and those are proving to be a little more challenging then expected, but I should eventually be able to sort this out. |
Awesome! Thanks for sticking with it. |
I'm sorry but I really can't find a way to write a good test for this. One of the main problem is that I struggle to correctly load a dummy plugin if it doesn't reside in Do you have a real interest/need to thoroughly test the plugin observer pattern? (Is it worth refactoring the code and putting in place the infrastructure to do this?) If so, could you share some leads because I'm seriously hitting a wall now. |
No worries! Let's merge without a test for now and, later, work out the details. If you're interested, we can cook up a clean strategy in a new issue. In the mean time, would you mind rolling back the current test code? With that and a changelog entry, we can merge now. |
All right let me finalize this then. Do you prefer history rewrite or revert commits? |
For example, this led beets-check to not recompute hashes when doing beet clearart [query]. Further operations on the file(s) would then trigger beets-check to issue integrity warnings.
This method already groups reading the config, managing file I/O and exceptions, as well as sending events to the plugins, so it's really easier and cleaner to do it that way. Note that passing 'images':None as tags to update correctly triggers beets to delete the images tag altogether.
I went with rewriting history and used this as an opportunity to cleanly rebase on top of master (also because I wanted to try rebasing rather than merging as a way to contribute.). I hope it's ok for you. Also I took care of the changelog. I didn't put a reference to the embedart plugin at the beginning because I think the fix happened at the core level, I don't know if it's how you'd assess it. It makes me a bit uncomfortable plugging in my name like that in the changelog 😊. but at least now hopefully you'll juste have to presse the big As always thank you for your responsiveness. I kept the raw commits of my experimentation with tests on another branch, I will probably try to have a fresh look at this some day. |
This looks perfect! Rewriting the history is just fine (for the record, either way is cool with me). And you're absolutely right to thank yourself; you deserve at least that. 😃 |
Rewrite the clearart method in order to send write events to the plugins.
Currently,
beet clearart
doesn't notify plugins that some files are modified. This can be a problem when for example using the beets-check plugin because checksums aren't recomputed and the modified files are then detected as not intact during subsequent operations.I finally settled on fixing this by using the try_write method which allows to simplify the code and centralizes the event sending so that this functionality isn't left out in the future. However, by doing that,
beet clearart
doesn't delete the image tag, but just erases its value. I don't know if this could be an issue.The beets-check plugin is the only one I know which needs to be aware of a
beet clearart
operation so I don't know if I can write tests for this. Can external plugins be called in the test suite?